﻿#include "PlayerOnQMedia.h"
#include "qobject.h"


#include <QWidget>

PlayerOnQMedia::PlayerOnQMedia(QObject *parent)
    : PlayerBase{parent}
{
    m_player = new QMediaPlayer(this);
    m_audioOutput = new QAudioOutput();
    m_player->setAudioOutput(m_audioOutput);
}

PlayerOnQMedia::~PlayerOnQMedia()
{
    
}

bool PlayerOnQMedia::open(const QString &media)
{
    m_player->setSource(QUrl(media));
    return true;
}

bool PlayerOnQMedia::play()
{
    m_player->play();
    if(m_player->playbackState() == QMediaPlayer::PlayingState)
    {
        return true;
    }
    return false;
}

bool PlayerOnQMedia::pause()
{
    m_player->pause();
    if(m_player->playbackState() == QMediaPlayer::PausedState)
    {
        return true;
    }
    return false;
}

bool PlayerOnQMedia::stop()
{
    m_player->stop();
    if(m_player->playbackState() == QMediaPlayer::StoppedState)
    {
        return true;
    }
    return false;
}

//QP::PlaybackState PlayerOnQMedia::state() const
//{
//    return (QP::PlaybackState)m_player->playbackState();
//}

////显示层中的视图层该做的事
//void PlayerOnQMedia::setState(QP::PlaybackState state)
//{
//}

float PlayerOnQMedia::volume() const
{
    return m_audioOutput->volume();
}

void PlayerOnQMedia::setVolume(float volume)
{
    m_audioOutput->setVolume(volume);
}

bool PlayerOnQMedia::isMuted() const
{
    return m_audioOutput->isMuted();
}

void PlayerOnQMedia::setMuted(bool muted)
{
    m_audioOutput->setMuted(muted);
}

void PlayerOnQMedia::setPlaybackRate(float rate)
{
    m_player->setPlaybackRate(rate);
}

void PlayerOnQMedia::setVideoWidget(QObject* w)
{
    m_player->setVideoOutput(w);
}
